package com.sduept.nwld.dataserver.controller.riskalarm;

import com.sduept.bigdata.document.entity.core.RecordAttachment;
import com.sduept.bigdata.document.services.RecordAttachmentManager;
import com.sduept.bigdata.fault.common.ParamDesc;
import com.sduept.bigdata.fault.model.CTSaturation;
import com.sduept.bigdata.fault.special.maintenance.manager.CtsaturatedQueryManager;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.ParamManager;
import com.sduept.core.entity.SystemParameter;
import com.sduept.message.entity.AlarmMessageCheck;
import com.sduept.message.manager.AlarmMessageCheckManager;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import java.util.ArrayList;
import java.util.List;

@Named
@ViewScoped
public class CTSaReportController extends AbstractController {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */

	@Autowired
	private CtsaturatedQueryManager ct;
	@Autowired
	private ParamManager pc;
	@Autowired
    private AlarmMessageCheckManager amc;
	@Autowired
	private RecordAttachmentManager ram;
	
	private CTSaturation ctModel=null;
	private String ctHarMinValue;
	private String ctAreaMinValue;
	private AlarmMessageCheck check=null;
	
	private List<RecordAttachment> attachments = new ArrayList<>();
	
	private boolean areaGe;
	private boolean harmonicGe;
	
	
	@PostConstruct
	private void init() {
		SystemParameter har = pc.get(ParamDesc.CT_SATURATION_HARMONIC_MIN_VALUE);
		ctHarMinValue=har.getValue();
		SystemParameter area = pc.get(ParamDesc.CT_SATURATION_AREA_MIN_VALUE);
		ctAreaMinValue=area.getValue();
		String recordId=getParameter("oId");
		String msgId=getParameter("msgId");
		List<CTSaturation> cts=ct.getCTSaturationById(recordId);
		if(cts.size()>0){
			ctModel=cts.get(0);
			try {
				areaGe = Float.valueOf(ctModel.getAreaProportion()) > Float.valueOf(area.getValue());
				harmonicGe= Float.valueOf(ctModel.getSeventhPowerHarmonicProportion()) >
				Float.valueOf(har.getValue());
			} catch (NumberFormatException e) {
			}
		}
		check=amc.getAlarmMessageCheckByMsgId(msgId);
		if(null==check) {
			check=new AlarmMessageCheck();
		}
		attachments = ram.getAttachmentsByOId(check.getId());
    }

	public CTSaturation getCtModel() {
		return ctModel;
	}


	public void setCtModel(CTSaturation ctModel) {
		this.ctModel = ctModel;
	}



	public String getCtAreaMinValue() {
		return ctAreaMinValue;
	}


	public void setCtAreaMinValue(String ctAreaMinValue) {
		this.ctAreaMinValue = ctAreaMinValue;
	}


	public String getCtHarMinValue() {
		return ctHarMinValue;
	}


	public void setCtHarMinValue(String ctHarMinValue) {
		this.ctHarMinValue = ctHarMinValue;
	}


	public boolean isAreaGe() {
		return areaGe;
	}


	public void setAreaGe(boolean areaGe) {
		this.areaGe = areaGe;
	}


	public boolean isHarmonicGe() {
		return harmonicGe;
	}


	public void setHarmonicGe(boolean harmonicGe) {
		this.harmonicGe = harmonicGe;
	}


	public AlarmMessageCheck getCheck() {
		return check;
	}


	public void setCheck(AlarmMessageCheck check) {
		this.check = check;
	}


	public List<RecordAttachment> getAttachments() {
		return attachments;
	}


	public void setAttachments(List<RecordAttachment> attachments) {
		this.attachments = attachments;
	}

	
	
}